﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BIZ;

namespace VIEW
{
    public partial class ManagerModifyCourseVIEW : Form
    {
        public ManagerModifyCourseVIEW()
        {
            InitializeComponent();

            ShowAll();


        }

        public void ShowAll()
        {
            ManagerModifyCourseBIZ biz = new ManagerModifyCourseBIZ();
            DataTable dt = new DataTable();
            dt = biz.ShowAllCourse();
            dataGridView1.DataSource = dt;
            dataGridView1.Columns[0].HeaderText = "课程号";
            dataGridView1.Columns[1].HeaderText = "课程名";
            dataGridView1.Columns[2].HeaderText = "学分";  
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ManagerModifyCourseBIZ manage = new ManagerModifyCourseBIZ();
            DataTable dt = new DataTable();
            string courseId;
            if (textBox1.Text != string.Empty)
            {
                courseId = textBox1.Text;
                dt = manage.QueryByCourseID(courseId);
                dataGridView1.DataSource = dt;
            }
            else
            {
                MessageBox.Show("请确认正确输入了课程号");
            }
           

        }

        private void button2_Click(object sender, EventArgs e)
        {
            ManagerModifyCourseBIZ manage = new ManagerModifyCourseBIZ();
            DataTable dt = new DataTable();
            string courseName;
            if (textBox2.Text != string.Empty)
            {
                courseName = textBox2.Text;
                dt = manage.QueryByCourseName(courseName);
                dataGridView1.DataSource = dt;
            }
            else
            {
                MessageBox.Show("请确正确认输入了课程名");
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            bool b = false;
            ManagerModifyCourseBIZ biz = new ManagerModifyCourseBIZ();
            string courseId = textBox1.Text;
            string courseName=textBox2.Text;
            string credit =textBox3.Text;
            b = biz.AddCourse(courseId, courseName, credit);
            if (b)
            {
                Show();
                MessageBox.Show("增加成功");


            }
            else
            {
                MessageBox.Show("增加失败");
            }


        }

        private void button5_Click(object sender, EventArgs e)
        {
            bool b;
            ManagerModifyCourseBIZ biz = new ManagerModifyCourseBIZ();
            if (textBox1.Text != string.Empty)
            {
                string courseId = textBox1.Text;
               // string courseName = textBox2.Text;
                b = biz.DeletCourse(courseId);
                if (b)
                {
                    ShowAll();
                    MessageBox.Show(" 删除成功！");
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }


            }
            else
            {
                MessageBox.Show("请输入课程号！");
            }
            
        }

    

        private void button4_Click(object sender, EventArgs e)
        {
            bool b = false;
            ManagerModifyCourseBIZ biz = new ManagerModifyCourseBIZ();
            if (textBox1.Text != string.Empty && textBox2.Text != string.Empty && textBox3.Text != string.Empty)
            {
                string courseId = textBox1.Text;
                string courseName = textBox2.Text;
                string credit = textBox3.Text;
                b = biz.ModifyCourse(courseId, courseName, credit);
                if (b)
                {
                    ShowAll();
                    MessageBox.Show("修改成功！");
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
            else
            {
                MessageBox.Show("请确认信息填写完整！");
            }
        }

       
     
    }
}